package cn.openea.perpartner.meily.web.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import cn.openea.perpartner.meily.web.entity.Enterprise;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * (Enterprise)表数据库访问层
 *
 * @author Weird077
 * @since 2023-05-28 10:23:41
 */
public interface EnterpriseMapper extends BaseMapper<Enterprise> {

    /**
     * 按照企业名称和企业统一信用代码判断是否存在
     * @param enterpriseName 企业名称
     * @param organizationCode 企业统一信用代码
     * @return Integer
     */
    @Select("SELECT 1 FROM meily_enterprise WHERE enterprise_name = #{enterpriseName} or organization_code = #{organizationCode}")
    Integer existenceByNameOrOrganizationCode(@Param("enterpriseName") String enterpriseName,@Param("organizationCode") String organizationCode);

    /**
     * 按照企业名称和企业统一信用代码判断查询
     * @param enterpriseName 企业名称
     * @param organizationCode 企业统一信用代码
     * @return Enterprise
     */
    @Select("SELECT * FROM meily_enterprise WHERE enterprise_name = #{enterpriseName} or organization_code = #{organizationCode} LIMIT 1")
    Enterprise findByNameOrOrganizationCode(@Param("enterpriseName") String enterpriseName,@Param("organizationCode") String organizationCode);

    @Update("UPDATE meily_enterprise SET enterprise_top = enterprise_top - 1 WHERE enterprise_top > #{enterpriseTop}")
    void downgradeTop(Integer enterpriseTop);
}

